﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace FarmacieDAL
{
    public class ChitanteManager
    {
        private static List<Chitanta> toateChitantele;
        private static List<Detalii_Chitanta> detaliiChitante;

        private static FarmacieEntities entities;

        public static void Initialize(FarmacieEntities entitiesContext)
        {
            toateChitantele = new List<Chitanta>();
            detaliiChitante = new List<Detalii_Chitanta>();

            entities = entitiesContext;

            toateChitantele = entities.Chitanta.ToList();
            detaliiChitante = entities.Detalii_Chitanta.ToList();
        }

        public static void Refresh()
        {
            toateChitantele.Clear();
            detaliiChitante.Clear();

            entities.Refresh(RefreshMode.StoreWins, entities.Chitanta);

            toateChitantele.AddRange(entities.Chitanta);
            detaliiChitante = entities.Detalii_Chitanta.ToList();

            RetetaManager.Refresh();
        }

        public static List<Chitanta> ToateChitantele
        {
            get
            {
                return toateChitantele;
            }
        }

        public static List<Vanzare> GetVanzariByChitanta(Chitanta chitanta)
        {
            List<Vanzare> result = new List<Vanzare>();

            foreach (Detalii_Chitanta detalii in detaliiChitante)
                if (detalii.Id_Chitanta.Equals(chitanta.Id_Chitanta))
                    result.Add(detalii.Vanzare);

            return result;
        }
    }
}
